<template>
	<view>
		<u-loading-page :loading="true" fontSize="57" iconSize="105" loadingMode="spinner" loadingText="loading">
		</u-loading-page>
	</view>
</template>

<script>
	import {
		mapActions
	} from 'vuex'
	export default {
		data() {
			return {

			}
		},
		methods: {
			...mapActions(['loginAction']),
		},
		mounted() {
			uni.login({
				provider: 'weixin', //使用微信登录
				onlyAuthorize: true,
				success: loginRes => {
					if (loginRes.errMsg !== "login:ok") {
						uni.showToast({
							"title": "登录失败"
						})
						return;
					}
					let code = loginRes.code;
					uni.$u.http.get(`${this.urlConfig.appServerPrefix}/wx/login`, {
						params: {
							js_code: code
						}
					}).then(res => {
						if (res.data.code != 100) {
							uni.showToast({
								title: "登录失败"
							});
						} else {
							this.loginAction(res.data.extend.user.nickName);
							uni.setStorageSync('token', res.data.extend.user.token);
							uni.switchTab({
								url: '/pages/index/index'
							});
						}
					}).catch(err => {
						console.log(err)
					});
				}
			});
		}
	}
</script>

<style>

</style>
